#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 255;

int n, m;
char s[N][N];
pii f[N][N];
int sz[N][N];
void init(int n, int m) {
  rep(i, 1, n) rep(j, 1, m) {
    f[i][j] = pii(i, j);
    sz[i][j] = 1;
  }
}
pii find(pii x) {
  if (f[x.first][x.second] == x) return x;
  return f[x.first][x.second] = find(f[x.first][x.second]);
}
void merge(pii a, pii b) {
  pii fa = find(a), fb = find(b);
  if (fa == fb) return;
  f[fb.first][fb.second] = fa;
  sz[fa.first][fa.second] += sz[fb.first][fb.second];
}
int L[N][N], U[N][N];
int UL[N][N], UR[N][N];
void init_dp() {
  rep(i, 1, n) rep(j, 1, m) {
    L[i][j] = U[i][j] = UL[i][j] = UR[i][j] = s[i][j] - '0';
    if (s[i][j] == '1') {
      if (j - 1 >= 1) L[i][j] = L[i][j - 1] + 1;
      if (i - 1 >= 1) U[i][j] = U[i - 1][j] + 1;
      if (i - 1 >= 1 && j - 1 >= 1) UL[i][j] = UL[i - 1][j - 1] + 1;
      if (i - 1 >= 1 && j + 1 <= m) UR[i][j] = UR[i - 1][j + 1] + 1;
    }
  }
}
bool check(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }
void solve() {
  cin >> n >> m;
  rep(i, 1, n) rep(j, 1, m) cin >> s[i][j];
  init_dp();
  init(n, m);
  rep(x, 1, n) rep(y, 1, m) {
    if (s[x][y] == '0') continue;
    rep(dx, -1, 1) rep(dy, -1, 1) {
      int nx = x + dx, ny = y + dy;
      if (nx < 1 || nx > n || ny < 1 || ny > m) continue;
      if (s[nx][ny] == '1') {
        merge(pii(x, y), pii(nx, ny));
      }
    }
  }
  int ans = 0;
  rep(i, 1, n) rep(j, 1, m) {
    if (s[i][j] == '0') continue;
    pii fij = find(pii(i, j));
    int num = sz[fij.first][fij.second];
    if (num % 4) continue;
    int len = num / 4;
    // top left
    {
      int x1 = i, y1 = j;
      int x2 = i, y2 = j + len;
      int x3 = i + len, y3 = j;
      int x4 = i + len, y4 = j + len;
      if (check(x1, y1) && check(x2, y2) && check(x3, y3) && check(x4, y4)) {
        if (L[x2][y2] == len + 1 && U[x3][y3] == len + 1 &&
            U[x4][y4] == len + 1 && L[x4][y4] == len + 1)
          ans++;
      }
    }
    // top mid
    {
      int x1 = i, y1 = j;
      int x2 = i + len, y2 = j - len;
      int x3 = i + len, y3 = j + len;
      int x4 = i + len * 2, y4 = j;
      if (check(x1, y1) && check(x2, y2) && check(x3, y3) && check(x4, y4)) {
        if (UR[x2][y2] == len + 1 && UL[x3][y3] == len + 1 &&
            UL[x4][y4] == len + 1 && UR[x4][y4] == len + 1)
          ans++;
      }
    }
  }
  cout << ans << endl;
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}